home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / CONSTRAI / EXTERNAL.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  6.4 KB  |  177 lines

  1.  
  2. package sub_arctic.constraints;
  3.  
  4. import java.util.Vector;
  5.  
  6. /**
  7.  * This abstract class provides that base class for all "external" (aka 
  8.  * heavyweight) constraints. External constraints can provide values from
  9.  * any source capable of supporting this protocol (which includes operations 
  10.  * attaching and detaching dependency edges, retrieving or computing a value,
  11.  * and indicating the stored or computed value has been changed).<p>
  12.  *
  13.  * @author Scott Hudson
  14.  */
  15. public abstract class external_constraint 
  16. implements value_provider, value_consumer {
  17.  
  18.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  19.  
  20.   /** Local mark for breaking cycles.  This is true while a mark out-of-date
  21.    *  traversal which has passed through this constraint is still going on.
  22.    *  if the traversal reaches a constraint with this value set it indicates
  23.    *  a cycle.
  24.    */
  25.   protected boolean _doing_ood;
  26.  
  27.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  28.   
  29.   /** The set of things we notify when values are out-of-date.  This Vector
  30.    *  contains consumer_part_ref objects. */
  31.   protected Vector _notify_list;
  32.  
  33.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  34.  
  35.   /** Default constructor. */
  36.   public external_constraint()
  37.     {
  38.       /* probably only have one thing to notify, so build a small vector */
  39.       _notify_list = new Vector(1);
  40.  
  41.       /* not doing out-of-date propagation */
  42.       _doing_ood = false;
  43.     }
  44.  
  45.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  46.  
  47.   /** 
  48.    * Compute an up-to-date copy of (or reference to) the value produced by this
  49.    * constraint.  Here part_number is ignored since we only provide one value.
  50.    * This gets overridden to provide the actual computation done by this 
  51.    * constraint.<p>
  52.    *
  53.    * @param int part_number the internal part number for the value desired.  In
  54.    *                        this case only part 0 is supported, so this is 
  55.    *                        ignored.
  56.    */
  57.    public abstract Object get_value(int part_number);
  58.  
  59.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  60.  
  61.   /** 
  62.    * Register something as interested in (dependent on) one of the parts of 
  63.    * this object.  The entity registered is a part within a value_consumer 
  64.    * object.  Whenever a value represented by this value_provider changes 
  65.    * (or might change), the value_ood() method must be invoked on each 
  66.    * currently registered (object,part).  Here we ignore on_part_num since
  67.    * we only have one part.<p>
  68.    *
  69.    * @param int on_part_num         the part of this object we are attaching 
  70.    *                                the dependent to (in this case ignored 
  71.    *                                since we only have one part).
  72.    * @param value_consumer dep_obj  the dependent object.
  73.    * @param int            dep_part the part within that object which is 
  74.    *                                dependent.
  75.    */
  76.   public void attach_dependent(
  77.     int            on_part_num, 
  78.     value_consumer dep_obj, 
  79.     int            dep_part)
  80.     {
  81.       /* add the object part to our notify list */
  82.       _notify_list.addElement(new consumer_part_ref(dep_obj, dep_part));
  83.     }
  84.  
  85.    //had:
  86.    //* @exception bad_value if an invalid part number is given
  87.  
  88.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  89.  
  90.   /** 
  91.    * Remove an (object,part) pair from the dependent (interested in) list. 
  92.    * Here we ignore on_part_num since we only have one part.<p>
  93.    *
  94.    * @param int            on_part_num the part number of this object the 
  95.    *                                   dependent was attached to (ignored here).
  96.    * @param value_consumer dep_obj     the previously dependent object.
  97.    * @param int            dep_part    the previously dependent part of that 
  98.    *                                   object.
  99.    */
  100.   public void detach_dependent(
  101.     int            on_part_num, 
  102.     value_consumer dep_obj, 
  103.     int            dep_part)
  104.     {
  105.       /* remove the part from our notify list */
  106.       _notify_list.removeElement(new consumer_part_ref(dep_obj, dep_part));
  107.     }
  108.  
  109.    //had:
  110.    //* @exception bad_value if an invalid part number is given
  111.    //* @exception general
  112.  
  113.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  114.  
  115.   /** 
  116.    * Indicate to this constraint that a value it depends on (a part of a 
  117.    * value_provider object that it is interested in) has, or might have, 
  118.    * changed value.  Here we just pass this on to others that depend on us 
  119.    * (being sure to break any cycles).<p>
  120.    *
  121.    * @param int            for_part_here the part of this object interested in 
  122.    *                                     the value (here this is ignored since 
  123.    *                                     we only have one part).
  124.    * @param value_provider prov_obj      the object providing the value we are 
  125.    *                                     interested in.
  126.    * @param int            prov_part     the part of the above object we are 
  127.    *                                     interested in.
  128.    */
  129.    public void value_ood(
  130.      int            for_part_here, 
  131.      value_provider prov_obj, 
  132.      int            prov_part)
  133.      {
  134.        consumer_part_ref notify_item;
  135.  
  136.        /* if we are in a cycle, break it */
  137.        if (!_doing_ood)
  138.      {
  139.        /* don't do this again */
  140.        _doing_ood = true;
  141.  
  142.            /* pass this on to our own interest set */
  143.        for (int i = 0; i < _notify_list.size(); i++)
  144.          {
  145.            /* pull out the item and notify it */
  146.            notify_item = (consumer_part_ref)_notify_list.elementAt(i);
  147.            notify_item.obj.value_ood(notify_item.part_num, this, 0);
  148.          }
  149.      }
  150.        _doing_ood = false;
  151.      }
  152.  
  153.    //had
  154.    //* @exception bad_value
  155.    //* @exception general
  156.  
  157.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  158.  
  159. }
  160.   
  161. /*=========================== COPYRIGHT NOTICE ===========================
  162.  
  163. This file is part of the subArctic user interface toolkit.
  164.  
  165. Copyright (c) 1996 Scott Hudson and Ian Smith
  166. All rights reserved.
  167.  
  168. The subArctic system is freely available for most uses under the terms
  169. and conditions described in 
  170.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  171. and appearing in full in the lib/interactor.java source file.
  172.  
  173. The current release and additional information about this software can be 
  174. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  175.  
  176. ========================================================================*/
  177.